home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / AMReminder / Add.p next >
Encoding:
Text File  |  1998-10-30  |  4.5 KB  |  200 lines  |  [TEXT/CWIE]

  1. { Add.p -- Modal dialog }
  2. { Created 10/30/98 1:03 PM by AppMaker }
  3.  
  4. Unit Add;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     TextEdit,
  16.     DReminder,
  17.     AMDialog;
  18.  
  19. type
  20.     CAdd        = object (AMDialog)
  21.  
  22.     {data members}
  23.         mData:        DReminder;
  24.  
  25.     mOKHandle:        ControlHandle;
  26.     mCancelHandle:        ControlHandle;
  27.     mDate2Handle:        ControlHandle;
  28.     mTime2Handle:        ControlHandle;
  29.     mMessage2Handle:        ControlHandle;
  30.     mDisplayIconHandle:        ControlHandle;
  31.     mDisplayAlertHandle:        ControlHandle;
  32.     mPlaySoundHandle:        ControlHandle;
  33.     mSoundPopupHandle:        ControlHandle;
  34.  
  35.     {methods - public}
  36.         Procedure ConnectToData    (inData:    AMSignaler); Override;
  37.  
  38.     {methods - internal}
  39.         Procedure FinishMake; Override;
  40.         Procedure DoItem    (inItemHit:    SInt16); Override;
  41.         Procedure DataChanged    (inDataID:    longint); Override;
  42.  
  43.     end;
  44.  
  45. {----------}
  46. Function NewAdd: CAdd;
  47.  
  48. {----------}
  49. Function GetAdd    (ioData:    DReminder): Boolean;
  50.  
  51. {----------}
  52. Implementation
  53.  
  54. Uses
  55.     ResourceDefs,
  56.     ControlUtils,
  57.     Miscellany;
  58.  
  59. const
  60.     kOKButton        = 1;
  61.     kCancelButton        = 2;
  62.     kLogoPicture        = 3;
  63.     kAddReminderForLabel        = 4;
  64.     kDateLabel        = 5;
  65.     kDate2Field        = 6;
  66.     kTimeLabel        = 7;
  67.     kTime2Field        = 8;
  68.     kMessageLabel        = 9;
  69.     kMessage2Field        = 10;
  70.     kWhenRemindingLabel        = 11;
  71.     kDisplayIconCheck        = 12;
  72.     kDisplayAlertCheck        = 13;
  73.     kPlaySoundCheck        = 14;
  74.     kSoundPopupPopup        = 15;
  75.  
  76.  
  77. {----------}
  78. Function NewAdd: CAdd;
  79. var
  80.     dialog:        CAdd;
  81. begin
  82.     dialog := nil;
  83.     New (dialog);
  84.  
  85.     if dialog <> nil then begin
  86.         dialog.Initialize;
  87.     end;
  88.     NewAdd := dialog;
  89. end;
  90.  
  91. {----------}
  92. Function GetAdd (
  93.     ioData:        DReminder): Boolean;
  94. Var
  95.     result:            Boolean;
  96.     dialog:            CAdd;
  97. begin
  98.     result := false;
  99.     dialog := NewAdd;
  100.  
  101.     result := dialog.RunModal (DLOG_Add, ioData);
  102.  
  103.     dialog.Free;
  104.     Dispose (dialog);
  105.  
  106.     GetAdd := result;
  107. end;
  108.  
  109. {----------}
  110. Procedure CAdd.FinishMake;
  111. var
  112.     errCode:        OSErr;
  113. begin
  114.     mOKHandle := GetControlItem (kOKButton);
  115.     SetDefaultState (mOKHandle, true);
  116.     errCode := SetDialogDefaultItem (mDialog, kOKButton);
  117.     mCancelHandle := GetControlItem (kCancelButton);
  118.     errCode := SetDialogCancelItem (mDialog, kCancelButton);
  119.     mDate2Handle := GetControlItem (kDate2Field);
  120.     mTime2Handle := GetControlItem (kTime2Field);
  121.     mMessage2Handle := GetControlItem (kMessage2Field);
  122.     mDisplayIconHandle := GetControlItem (kDisplayIconCheck);
  123.     mDisplayAlertHandle := GetControlItem (kDisplayAlertCheck);
  124.     mPlaySoundHandle := GetControlItem (kPlaySoundCheck);
  125.     mSoundPopupHandle := GetControlItem (kSoundPopupPopup);
  126. end;
  127.  
  128. {----------}
  129. Procedure CAdd.ConnectToData (
  130.     inData:        AMSignaler); Override;
  131. begin
  132.     inherited ConnectToData (inData);
  133.     mData := DReminder (inData);
  134.  
  135.     SetClockDateTime (mDate2Handle, mData.GetDateTime);
  136.     SetClockDateTime (mTime2Handle, mData.GetDateTime);
  137.     SetControlText (mMessage2Handle, mData.GetMessage);
  138.     SetControlValue (mDisplayIconHandle, ord (mData.GetShowIcon));
  139.     SetControlValue (mDisplayAlertHandle, ord (mData.GetShowAlert));
  140.     SetControlValue (mPlaySoundHandle, ord (mData.GetPlaySound));
  141.     SetControlValue (mSoundPopupHandle, mData.GetSoundIndex);
  142. end;
  143.  
  144. {----------}
  145. Procedure CAdd.DoItem (
  146.     inItemHit:        SInt16);
  147. begin
  148.     case inItemHit of
  149.     kOKButton:
  150.             SetResult (true);
  151.     kCancelButton:
  152.             SetResult (false);
  153.     kDate2Field:
  154.             mData.SetDateTime (GetClockDateTime (mDate2Handle));
  155.     kTime2Field:
  156.             mData.SetDateTime (GetClockDateTime (mTime2Handle));
  157.     kMessage2Field:
  158.             mData.SetMessage (GetEditTextStr (mMessage2Handle));
  159.     kDisplayIconCheck:
  160.             mData.SetShowIcon (ToggleCheckbox (mDisplayIconHandle));
  161.     kDisplayAlertCheck:
  162.             mData.SetShowAlert (ToggleCheckbox (mDisplayAlertHandle));
  163.     kPlaySoundCheck:
  164.             mData.SetPlaySound (ToggleCheckbox (mPlaySoundHandle));
  165.     kSoundPopupPopup: begin
  166.             mData.SetSoundIndex (GetControlValue (mSoundPopupHandle));
  167.         end;
  168.  
  169.     end; {switch}
  170. end;
  171.  
  172. {----------}
  173. Procedure CAdd.DataChanged (
  174.     inDataID:        longint); Override;
  175. begin
  176.     if inDataID = idDateTime then begin
  177.         SetClockDateTime (mDate2Handle, mData.GetDateTime);
  178.     end;
  179.     if inDataID = idDateTime then begin
  180.         SetClockDateTime (mTime2Handle, mData.GetDateTime);
  181.     end;
  182.     if inDataID = idMessage then begin
  183.         SetControlText (mMessage2Handle, mData.GetMessage);
  184.     end;
  185.     if inDataID = idShowIcon then begin
  186.         SetControlValue (mDisplayIconHandle, ord (mData.GetShowIcon));
  187.     end;
  188.     if inDataID = idShowAlert then begin
  189.         SetControlValue (mDisplayAlertHandle, ord (mData.GetShowAlert));
  190.     end;
  191.     if inDataID = idPlaySound then begin
  192.         SetControlValue (mPlaySoundHandle, ord (mData.GetPlaySound));
  193.     end;
  194.     if inDataID = idSoundIndex then begin
  195.         SetControlValue (mSoundPopupHandle, mData.GetSoundIndex);
  196.     end;
  197. end;
  198.  
  199. End.
  200.